package com.example.springbootchapter09.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTask {
    // 每5秒执行一次任务
    @Scheduled(fixedRate = 5000)
    public void fixedRateTask() {
        System.out.println("定时任务（固定频率）执行中：" + System.currentTimeMillis());
    }
    // 每天凌晨2点执行任务
    @Scheduled(cron = "0 0 2 * * *")
    public void cronTask() {
        System.out.println("定时任务（cron表达式）执行中：" + System.currentTimeMillis());
    }
}